package com.teangtang.fly.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Data;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Entity
@Data
public class Flight { // 航班
    @Id
    // 班次ID（自动生成，逻辑为航班号加日期）
    private String flightId;
    private String flightNumber;
    private Date departureTime;
    private Date arrivalTime;
    private String companyName;

    @ManyToOne
    @JoinColumn(name = "plane_id")
    @JsonBackReference
    private Plane plane;

    @ManyToOne
    @JoinColumn(name = "airline_number")
    @JsonBackReference
    private Airline airline;

    private String status; // 状态 0-待机 1-飞行中 2-已到达 3-延期 4-取消
    private Long frequency; // 频率 1-每天 2-隔天 3-每周 4-每月
    //始飞日期
    @Temporal(TemporalType.DATE)
    private Date startDate;

    @OneToMany(mappedBy = "flight", cascade = CascadeType.ALL, orphanRemoval = true)
    @JsonManagedReference
    private List<Ticket> Tickets;

    @OneToMany(mappedBy = "flight", cascade = CascadeType.ALL,orphanRemoval = true)
    @JsonManagedReference
    private List<CabinPrice> cabinPrices; // 存储每个舱段的票价
}